package com.hex.ds.hdtp.core.inf.metadata.service.impl;

import cn.hutool.core.util.StrUtil;
import com.hex.ds.hdtp.core.inf.common.enums.FieldType;
import com.hex.ds.hdtp.core.inf.common.utils.JdbcUtil;
import com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity;
import com.hex.ds.hdtp.core.inf.metadata.po.SourceConfInfoPo;
import com.hex.ds.hdtp.core.inf.metadata.repository.ISourceConfInfoRepository;
import com.hex.ds.hdtp.core.inf.metadata.service.ISourceMethodService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Package com.hex.ds.hdtp.core.inf.metadata.service.impl
 * @ClassName AbstractSourceMethodService
 * @Description 元数据管理抽象类
 * @Author jian.qiao
 * @Date 2023/10/31 19:56
 * @Version v1.0
 **/
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public abstract class AbstractSourceMethodService implements ISourceMethodService {
    private final ISourceConfInfoRepository sourceConfInfoRepository;

    /**
     * @Method connection <br>
     * @Param
     * @Param sourceConfInfoList <br>
     * @Return java.lang.Boolean <br>
     * @Description 测试连接<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:56 <br>
     * @Version V1.0<br>
     */
    @Override
    public Boolean connection(List<SourceConfInfoPo> sourceConfInfoList) {
        return JdbcUtil.testJdbcConnection(sourceConfInfoList);
    }

    /**
     * @Method schemas <br>
     * @Param
     * @Param sourceCode <br>
     * @Return java.util.List<java.lang.String> <br>
     * @Description 获取指定数据源的库集合<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:56 <br>
     * @Version V1.0<br>
     */
    @Override
    public List<String> schemas(String sourceCode) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        ResultSet resultSet = null;
        List<String> resultList = new ArrayList();
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            resultSet = JdbcUtil.executeQuerySql(jdbcStatement, getSchemasSql());
            while (resultSet.next()) {
                resultList.add(resultSet.getString(1));
            }
        } catch (SQLException e) {
            log.error("获取指定数据源的库集合", e.getStackTrace());
        } finally {
            JdbcUtil.closeConnection(resultSet);
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
        return resultList;
    }

    /**
     * @Method tables <br>
     * @Param
     * @Param sourceCode
     * @Param schemaName <br>
     * @Return java.util.List<java.lang.String> <br>
     * @Description 获取指定数据源和库的表集合<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:56 <br>
     * @Version V1.0<br>
     */
    @Override
    public List<String> tables(String sourceCode, String schemaName) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        List<String> resultList = new ArrayList();
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            ResultSet resultSet = JdbcUtil.executeQuerySql(jdbcStatement, getTablesSql(schemaName));
            while (resultSet.next()) {
                ResultSetMetaData metaData = resultSet.getMetaData();
                for (int i = 1; i <= metaData.getColumnCount(); i++) {
                    resultList.add(resultSet.getString(i));
                }
            }
        } catch (SQLException e) {
            log.error("获取指定数据源和库的表集合", e.getStackTrace());
        } finally {
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
        return resultList;
    }

    /**
     * @Method procedures <br>
     * @Param
     * @Param sourceCode
     * @Param schemaName <br>
     * @Return java.util.List<java.lang.String> <br>
     * @Description 获取指定数据源和库的存储过程集合<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:56 <br>
     * @Version V1.0<br>
     */
    @Override
    public List<String> procedures(String sourceCode, String schemaName) {
        return null;
    }

    /**
     * @Method proceduresContent <br>
     * @Param
     * @Param sourceCode
     * @Param schemaName
     * @Param proceduresName <br>
     * @Return java.lang.String <br>
     * @Description 获取指定存储过程的内容<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    @Override
    public String proceduresContent(String sourceCode, String schemaName, String proceduresName) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        String proceduresContent = null;
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            ResultSet resultSet = JdbcUtil.executeQuerySql(jdbcStatement, queryProceduresContentSql(schemaName, proceduresName));
            while (resultSet.next()) {
                proceduresContent = getProcedureContentFromResultSet(resultSet);
            }
        } catch (SQLException e) {
            log.error("获取指定存储过程的内容", e.getStackTrace());
        } finally {
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
        return proceduresContent;
    }

    /**
     * @Method tableStructure <br>
     * @Param
     * @Param sourceCode
     * @Param schemaName
     * @Param tableName <br>
     * @Return java.util.List<com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity> <br>
     * @Description 获取指定数据源和库、表的元数据<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    @Override
    public List<TableFieldsEntity> tableStructure(String sourceCode, String schemaName, String tableName) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        List<TableFieldsEntity> resultList = new ArrayList();
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            ResultSet resultSet = JdbcUtil.executeQuerySql(jdbcStatement, queryTableStructureSql(schemaName, tableName));
            while (resultSet.next()) {
                ResultSetMetaData metaData = resultSet.getMetaData();
                Map<String, String> tableFieldsMap = new HashMap<>();
                for (int i = 1; i <= metaData.getColumnCount(); i++) {
                    tableFieldsMap.put(metaData.getColumnName(i), resultSet.getString(i));
                }
                resultList.add(toTableFieldsBean(tableFieldsMap));
            }
        } catch (SQLException e) {
            log.error("获取指定数据源和库、表的元数据", e.getStackTrace());
        } finally {
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
        //筛选的操作
        return resultList;
    }

    /**
     * @Method tableStructure <br>
     * @Param
     * @Param sourceCode
     * @Param schemaName
     * @Param tableName <br>
     * @Return java.util.List<com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity> <br>
     * @Description 获取指定数据源和库、表的元数据<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    @Override
    public List<TableFieldsEntity> tableStructureByType(String sourceCode, String schemaName, String tableName, String fieldType) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        List<TableFieldsEntity> resultList = new ArrayList();
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            ResultSet resultSet = JdbcUtil.executeQuerySql(jdbcStatement, queryTableStructureSql(schemaName, tableName));
            while (resultSet.next()) {
                ResultSetMetaData metaData = resultSet.getMetaData();
                Map<String, String> tableFieldsMap = new HashMap<>();
                for (int i = 1; i <= metaData.getColumnCount(); i++) {
                    tableFieldsMap.put(metaData.getColumnName(i), resultSet.getString(i));
                }
                resultList.add(toTableFieldsBean(tableFieldsMap));
            }
        } catch (SQLException e) {
            log.error("获取指定数据源和库、表的元数据", e.getStackTrace());
        } finally {
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
        List<String> fieldTypes = FieldType.fromFieldType(fieldType);
        List<TableFieldsEntity> afterDealFields = resultList.stream().filter(e -> fieldTypes.contains(e.getColumnType().toUpperCase())).collect(Collectors.toList());
        return afterDealFields;
    }

    /**
     * @Method executeUpdatetSql <br>
     * @Param
     * @Param sourceCode
     * @Param updateSql <br>
     * @Return void 执行指定SQL<br>
     * @Description <br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    @Override
    public void executeUpdatetSql(String sourceCode, String updateSql) {
        List<SourceConfInfoPo> sourceConfInfoPoList = sourceConfInfoRepository.queryListBySourceCode(sourceCode);
        Connection jdbcConnection = null;
        Statement jdbcStatement = null;
        try {
            jdbcConnection = JdbcUtil.getJdbcConnection(sourceConfInfoPoList);
            jdbcStatement = JdbcUtil.createJdbcStatement(jdbcConnection);
            JdbcUtil.executeUpdatetSql(jdbcStatement, updateSql);
        } finally {
            JdbcUtil.closeConnection(jdbcConnection, jdbcStatement);
        }
    }

    /**
     * @Method queryProceduresContentSql <br>
     * @Param
     * @Param schemaName
     * @Param proceduresName <br>
     * @Return java.lang.String <br>
     * @Description 查询存储过程内容sql<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    protected abstract String queryProceduresContentSql(String schemaName, String proceduresName);

    /**
     * @Method getProcedureContentFromResultSet <br>
     * @Param
     * @Param resultSet <br>
     * @Return java.lang.String <br>
     * @Description 获取存储过程内容sql<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    protected abstract String getProcedureContentFromResultSet(ResultSet resultSet) throws SQLException;

    /**
     * @Method toTableFieldsBean <br>
     * @Param
     * @Param tableFieldsMap <br>
     * @Return com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity <br>
     * @Description 字段转换处理<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    protected abstract TableFieldsEntity toTableFieldsBean(Map<String, String> tableFieldsMap);

    /**
     * @Method queryTableStructureSql <br>
     * @Param
     * @Param schemaName
     * @Param tableName <br>
     * @Return java.lang.String <br>
     * @Description 获取指定数据源和库、表的元数据sql<br>
     * @Author jian.qiao<br>
     * @Date 2023/10/31 19:57 <br>
     * @Version V1.0<br>
     */
    protected abstract String queryTableStructureSql(String schemaName, String tableName);

    protected ISourceConfInfoRepository getSourceConfInfoRepository() {
        return sourceConfInfoRepository;
    }

    /**
     * @Method getSchemasSql
     * @Param
     * @Return java.lang.String
     * @Description 获取数据库Schemas的SQL
     * @Author gj.xu
     * @Date 2024/2/2 15:40
     * @Version V2.0
     */
    @Override
    public String getSchemasSql() {
        return "SHOW DATABASES";
    }

    /**
     * @Method getTablesSql
     * @Param schemaName
     * @Return java.lang.String
     * @Description 获取数据库Tables的SQL
     * @Author gj.xu
     * @Date 2024/2/2 15:44
     * @Version V2.0
     */
    @Override
    public String getTablesSql(String schemaName) {
        return StrUtil.format("SHOW TABLES IN `{}`", schemaName);
    }

    /**
     * @Method getTableDataNumSql
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取表的数据量SQL
     * @Author gj.xu
     * @Date 2024/1/29 15:28
     * @Version V2.0
     */
    @Override
    public String getTableDataNumSql(String schema, String table, String whereSql) {
        String querySql = "SELECT COUNT(*) FROM {}.{} {}";
        return StrUtil.format(querySql, schema, table, whereSql);
    }

    /**
     * @Method getTableIsHaveDataSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取表是否有数据SQL
     * @Author gj.xu
     * @Date 2024/1/29 16:12
     * @Version V2.0
     */
    @Override
    public String getTableIsHaveDataSql(String schema, String table) {
        String querySql = "SELECT COUNT(*) FROM {}.{}";
        return StrUtil.format(querySql, schema, table);
    }


    /**
     * @Method getTableAllFieldSql
     * @Param fields
     * @Param schema
     * @Param table
     * @Param partitionsWhereSql
     * @Param sortField
     * @Return java.lang.String
     * @Description 获取全字段明细对比SQL
     * @Author gj.xu
     * @Date 2024/1/30 18:14
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldSql(String fields, String schema, String table, String partitionsWhereSql, String sortField) {
        String querySql = "SELECT {} FROM {}.{} {} ORDER BY {}";
        return StrUtil.format(querySql, fields, schema, table, partitionsWhereSql, sortField);
    }


    /**
     * @Method getTableAllFieldSqlLimitSql
     * @Param fields
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Param extractScope
     * @Param offset
     * @Param sortField
     * @Return java.lang.String
     * @Description 获取分批比对全字段明细对比的SQL
     * @Author gj.xu
     * @Date 2024/2/1 20:53
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldSqlLimitSql(String fields, String schema, String table, String whereSql, Long extractScope, Long offset, String sortField) {
        String querySql = "SELECT {} FROM {}.{} {} ORDER BY {} limit {} offset {}";
        return StrUtil.format(querySql, fields, schema, table, whereSql, sortField, extractScope, offset);
    }

    /**
     * @Method getTableIsNullCountSql
     * @Param schema
     * @Param table
     * @Param field
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取字段为空总数SQL
     * @Author gj.xu
     * @Date 2024/1/30 19:15
     * @Version V2.0
     */
    @Override
    public String getTableIsNullCountSql(String schema, String table, String field, String whereSql) {
        String querySql = "SELECT COUNT(*) FROM {}.{} WHERE {} IS NULL {}";
        return StrUtil.format(querySql, schema, table, field, whereSql);
    }

    /**
     * @Method getTableDistinctCountSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取去重COUNT的SQL
     * @Author gj.xu
     * @Date 2024/1/30 19:29
     * @Version V2.0
     */
    @Override
    public String getTableDistinctCountSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT COUNT( DISTINCT {} ) FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }

    /**
     * @Method getTableGroupCountSql
     * @Param schema
     * @Param table
     * @Param field
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取分组COUNT的SQL
     * @Author gj.xu
     * @Date 2024/1/31 15:24
     * @Version V2.0
     */
    @Override
    public String getTableGroupCountSql(String schema, String table, String field, String whereSql) {
        String querySql = "SELECT COUNT(*) FROM {}.{} {} GROUP BY {}";
        return StrUtil.format(querySql, schema, table, whereSql, field);
    }

    /**
     * @Method getTableFieldGroupCountSql
     * @Param schema
     * @Param table
     * @Param field
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取字段COUNT的SQL
     * @Author gj.xu
     * @Date 2024/1/31 16:30
     * @Version V2.0
     */
    @Override
    public String getTableFieldGroupCountSql(String schema, String table, String field, String whereSql) {
        String querySql = "SELECT {} AS column_name,COUNT({}) AS total from  {}.{} {} group by {}";
        return StrUtil.format(querySql, field, field, schema, table, whereSql, field);
    }

    /**
     * @Method getTableFieldTrimSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取字段TRIM的SQL
     * @Author gj.xu
     * @Date 2024/1/31 19:06
     * @Version V2.0
     */
    @Override
    public String getTableFieldTrimSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT TRIM({}) FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }


    /**
     * @Method getTableFieldSumSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取字段SUM的SQL
     * @Author gj.xu
     * @Date 2024/1/31 19:39
     * @Version V2.0
     */
    @Override
    public String getTableFieldSumSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT SUM({}) FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }


    /**
     * @Method getTableLengthMaxSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取字段长度MAX的SQL
     * @Author gj.xu
     * @Date 2024/1/31 20:02
     * @Version V2.0
     */
    @Override
    public String getTableLengthMaxSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT MAX(LENGTH({})) AS max_length FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }


    /**
     * @Method getTableFieldLengthSumTrimSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取指定字段长度TRIM后SUM的SQL
     * @Author gj.xu
     * @Date 2024/2/1 10:33
     * @Version V2.0
     */
    @Override
    public String getTableFieldLengthSumTrimSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT SUM(LENGTH(TRIM({}))) FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }

    /**
     * @Method getTableFieldLengthSumSql
     * @Param field
     * @Param schema
     * @Param table
     * @Param whereSql
     * @Return java.lang.String
     * @Description 获取指定字段字段长度SUM的SQL
     * @Author gj.xu
     * @Date 2024/2/1 10:43
     * @Version V2.0
     */
    @Override
    public String getTableFieldLengthSumSql(String field, String schema, String table, String whereSql) {
        String querySql = "SELECT SUM(LENGTH({})) FROM {}.{} {}";
        return StrUtil.format(querySql, field, schema, table, whereSql);
    }


    /**
     * @Method getTableAllFieldNumSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取所有字段总数SQL
     * @Author gj.xu
     * @Date 2024/2/1 11:12
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldNumSql(String schema, String table) {
        String querySql = "DESCRIBE {}.{} ";
        return StrUtil.format(querySql, schema, table);
    }

    /**
     * @Method getTableAllFieldNameSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取所有字段名称SQL
     * @Author gj.xu
     * @Date 2024/2/1 11:44
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldNameSql(String schema, String table) {
        String querySql = "DESCRIBE {}.{} ";
        return StrUtil.format(querySql, schema, table);
    }


    /**
     * @Method getTableAllFieldLengthSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取所有字段长度SQL
     * @Author gj.xu
     * @Date 2024/2/1 14:20
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldLengthSql(String schema, String table) {
        String querySql = "SELECT COLUMN_NAME as column_name,COALESCE(CHARACTER_MAXIMUM_LENGTH, '0') as data_length FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = LOWER('{}') and TABLE_NAME = LOWER('{}')";
        return StrUtil.format(querySql, schema, table);
    }


    /**
     * @Method getTableFieldAccuracySql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取字段精度SQL
     * @Author gj.xu
     * @Date 2024/2/1 15:20
     * @Version V2.0
     */
    @Override
    public String getTableFieldAccuracySql(String schema, String table) {
        String querySql = "SELECT COLUMN_NAME as column_name, TRIM(COALESCE(numeric_scale, '0')) as column_accuracy FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = LOWER('{}') and TABLE_NAME = LOWER('{}')";
        return StrUtil.format(querySql, schema, table);
    }


    /**
     * @Method getTableAllFieldTypeSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取字段类型SQL
     * @Author gj.xu
     * @Date 2024/2/1 15:45
     * @Version V2.0
     */
    @Override
    public String getTableAllFieldTypeSql(String schema, String table) {
        String querySql = "SELECT column_name, CASE WHEN data_type = 'character varying' THEN 'varchar' WHEN data_type = 'timestamp without time zone' THEN 'timestamp' WHEN data_type = 'character' THEN 'char' ELSE data_type END as data_type FROM information_schema.columns WHERE TABLE_SCHEMA = LOWER('{}') AND TABLE_NAME = LOWER('{}')";
        return StrUtil.format(querySql, schema, table);
    }

    /**
     * @Method getTablePartitionFieldSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取分区字段的SQL
     * @Author gj.xu
     * @Date 2024/2/1 20:20
     * @Version V2.0
     */
    @Override
    public String getTablePartitionFieldSql(String schema, String table) {
        log.error("暂未支持获取分区字段的SQL");
        throw new RuntimeException("暂未支持获取分区字段的SQL");
    }


    /**
     * @Method getTableShowCreateTableSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取查询表建表语句的SQL
     * @Author gj.xu
     * @Date 2024/1/31 17:18
     * @Version V2.0
     */
    @Override
    public String getTableShowCreateTableSql(String schema, String table) {
        String querySql = "SHOW CREATE TABLE {}.{} ";
        return StrUtil.format(querySql, schema, table);
    }

    /**
     * @Method getDropTableSql
     * @Param schemaName
     * @Param tableName
     * @Return java.lang.String
     * @Description 获取Drop表的SQL
     * @Author gj.xu
     * @Date 2024/3/8 14:43
     * @Version V2.0
     */
    public String getDropTableSql(String schemaName, String tableName) {
        String querySql = "DROP TABLE IF EXISTS {}.{};\n";
        return StrUtil.format(querySql, schemaName, tableName);
    }

    /**
     * @Method getCreateTableHeaderSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取创建表时头部分SQL
     * @Author gj.xu
     * @Date 2024/2/1 17:18
     * @Version V2.0
     */
    @Override
    public String getCreateTableHeaderSql(String schema, String table) {
        String querySql = "CREATE TABLE {}.{} ( \n";
        return StrUtil.format(querySql, schema, table);
    }

    /**
     * @Method getCreateTableBodySql
     * @Param columnName
     * @Param columnType
     * @Param columnExt
     * @Return java.lang.String
     * @Description 获取创建表时Body部分SQL
     * @Author gj.xu
     * @Date 2024/2/1 17:36
     * @Version V2.0
     */
    public String getCreateTableBodySql(String columnName, String columnType, String columnExt, String columnComment) {
        String querySql = "{} {}{} {},\n";
        return StrUtil.format(querySql, columnName, columnType, columnExt, columnComment);
    }

    /**
     * @Method getCreateColCommentSql
     * @Param columnComment
     * @Return java.lang.String
     * @Description 获取创建表时字段Comment部分SQL
     * @Author gj.xu
     * @Date 2024/2/1 19:22
     * @Version V2.0
     */
    public String getCreateColCommentSql(String columnComment) {
        String querySql = "COMMENT '{}'";
        return StrUtil.format(querySql, columnComment);
    }
}
